﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_Modes;
using Zor_IDAL;
using Zor_Tools;
using System.Data;
using Dapper;
namespace Zor_DAL
{
    public class Zor_Evaluate_DAL<T> where T : class
    {
      
        /// <summary>
        /// 推送提交至审核
        /// create zhl by 17.3.31
        /// </summary>
        /// <param name="evaluate">评定对象</param>
        /// <returns>2--当前评议已推送-1操作失败1--操作成功的标识</returns>
        public static int Evaluate(Zor_Evaluate evaluate,string accpid)
        {
            var param = new DynamicParameters();
            param.Add("@Evaluate_Id", evaluate.Evaluate_Id);
            param.Add("@Acceptance_Id", accpid);
            param.Add("@Evaluate_TotalTax", evaluate.Evaluate_TotalTax);
            param.Add("@Evaluate_Rent", evaluate.Evaluate_Rent);
            param.Add("@Evaluate_PersonalTax", evaluate.Evaluate_PersonalTax);
            param.Add("@Evaluate_PropertyTax", evaluate.Evaluate_PropertyTax);
            param.Add("@Evaluate_Tax", evaluate.Evaluate_Tax);
            param.Add("@Evaluate_Comment", evaluate.Evaluate_Comment);
            param.Add("@Evaluate_State", evaluate.Evaluate_State);
            param.Add("@User_Id", RequestSession.GetSessionUser().User_Id);
            param.Add("@CreateTime", TimeHelper.ToTimeStamp(DateTime.Now));
            param.Add("@narid", 0, DbType.Int32, ParameterDirection.ReturnValue);
            using (IDbConnection conn = DapperConn.OpenSqlConnection())
            {
                var Answer = conn.Execute("Pro_Evaluate", param, null, null, CommandType.StoredProcedure);
                return param.Get<int>("@narid");
            }
        }

        /// <summary>
        /// 退回至评定
        /// create zhl by 17.3.31
        /// 评定状态(0正在评定,1已评定,2被退回,3退回到评议)
        /// </summary>
        /// <param name="aptid">受理单id</param>
        /// <param name="evaluate">评定对象</param>
        /// <param name="reviewid">退回意见</param>
        /// <returns></returns>
        public static BaseAnswer ReturnReview(Zor_Evaluate evaluate, string accpid)
        {

            List<string> lstsql = new List<string>();

            //更新评定状态
            lstsql.Add(string.Format("update [Zor_Review] set Review_State=2 ,Review_Remarks='" + evaluate.Evaluate_Comment + "' where Review_Id=" + evaluate.Review_Id + ""));
            //更新评议状态
            lstsql.Add(string.Format("update [Zor_Evaluate] set Evaluate_State=3  where Evaluate_Id=" + evaluate.Evaluate_Id + ""));
            //更新受理单表
            lstsql.Add(string.Format("update [Zor_Acceptance] set Acceptance_State=2 where Acceptance_Id=" + accpid + ""));
            //退回记录表增加数据
            lstsql.Add(string.Format("insert into Zor_ReturnRecord values(" + evaluate.Review_Id + ",'" + evaluate.Evaluate_Comment + "'," + RequestSession.GetSessionUser().User_Id + "," + TimeHelper.ToTimeStamp(DateTime.Now) + ",2)"));
            BaseAnswer bar = DapperTransaction.DoTransaction(lstsql);
            return bar;
        }
    }
}
